package rafael.bot;

import roshambo.Player;

public class MasterRafael implements Player{
	private Rafael rafael;
	private int[] key = {1,2,3,3,1,2,3,2,1,2,1,3,1,2,2,3,2,3,3,3,3,3};
	private int t;
	private boolean slave = true;

	public MasterRafael(int memory) {
		rafael = new Rafael(memory);
	}
	
	@Override
	public int play() {
		if(slave) {
			if(t < key.length) {
				return Model.bestAnswer(key[t]);
			}else {
				return 1;
			}
		}
		return rafael.play();
	}

	@Override
	public void receive(int result) {
		if((t < key.length && key[t] != result )|| (t >= key.length && result != 3)) {
			slave = false;
		}
		t++;
		if(!slave) {
			rafael.receive(result);
		}
	}

	@Override
	public void newGame(int games) {
		rafael.newGame(games);
		t = 0;
	}
}
